package de.ubschmidt.capi;

import java.nio.ByteBuffer;

/**
 *
 */
public class DataB3Resp
        extends CapiActiveMessage
        implements NcciProperty {

    /** The NCCI. */
    private int _ncci;

    private short _dataHandle;

    public DataB3Resp(final int ncci, final short dataHandle) {
        super(Command.DATA_B3_RESP);
        setNcci(ncci);
        setDataHandle(dataHandle);
    }

    public DataB3Resp(final DataB3Ind dataB3Ind) {
        this(dataB3Ind.getNcci(), dataB3Ind.getDataHandle());
    }

    /** {@inheritDoc} */
    public int getNcci() {
        return _ncci;
    }

    /** {@inheritDoc} */
    public void setNcci(final int ncci) {
        _ncci = ncci;
    }

    public short getDataHandle() {
        return _dataHandle;
    }

    public void setDataHandle(final short dataHandle) {
        _dataHandle = dataHandle;
    }

    /** {@inheritDoc} */
    protected void serializeTo(final ByteBuffer byteBuffer) {
        byteBuffer.putInt(_ncci);
        byteBuffer.putShort((short) 0);
        byteBuffer.put((byte) 0);
    }

    /** {@inheritDoc} */
    @Override
    public String toString() {
        String s = String.format(
                "%s[%s ncci=0x%08x handle=0x%04x]",
                getClass().getSimpleName(),
                super.toString(),
                getNcci(),
                getDataHandle());

        return s;
    }

}
